package com.cgbl.cg.adapter

import android.graphics.Typeface
import android.util.TypedValue
import com.blankj.utilcode.util.ColorUtils
import com.cgbl.cg.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.robot.base.model.CourseBean
import com.robot.base.model.TypeListBean
import com.robot.base.view.CgTextView

class HomeTabAdapter(var lineVisit: Boolean = true) :
    BaseQuickAdapter<TypeListBean, BaseViewHolder>(R.layout.app_item_home_tab) {
    var position = 0
    var tabChangeListener: TabChangeListener? = null

    public fun setMTabChangeListener(listener: TabChangeListener) {
        this.tabChangeListener = listener
    }

    override fun convert(holder: BaseViewHolder, item: TypeListBean) {
        val tvName = holder.getView<CgTextView>(R.id.item_tv_name)
        holder.setText(R.id.item_tv_name, item.typeName)

        if (lineVisit) {
            holder.setGone(R.id.item_view_line, position != holder.adapterPosition)
            tvName.setTextSize(
                TypedValue.COMPLEX_UNIT_SP, if (position == holder.adapterPosition) {
                    18f
                } else {
                    14f
                }
            )
        } else {
            holder.setGone(R.id.item_view_line, true)
            tvName.setTextColor(
                if (position == holder.adapterPosition) {
                    ColorUtils.getColor(R.color.app_color_cc2d2d)
                } else {
                    ColorUtils.getColor(R.color.app_color_42)
                }
            )
            tvName.setTextSize(
                TypedValue.COMPLEX_UNIT_SP, if (position == holder.adapterPosition) {
                    16f
                } else {
                    14f
                }
            )
        }

        tvName.typeface = if (position == holder.adapterPosition) {
            Typeface.DEFAULT_BOLD
        } else {
            Typeface.DEFAULT
        }
        tvName.setOnClickListener {
            position = holder.adapterPosition
            tabChangeListener?.tabChange(holder.adapterPosition, item.appCourseBaseVOS ?: listOf())
            notifyDataSetChanged()
        }
    }

    interface TabChangeListener {
        fun tabChange(position: Int, list: List<CourseBean>)
    }

}